import http from "@/utils/request";
import {ElMessage, ElMessageBox} from 'element-plus'

export function useDelete(functionMethod,callback) {

    const handleDelete=async (item) => {
        try {
            await ElMessageBox.confirm('确认删除该条数据吗？', '提示', {
                type: 'warning'
            })
            if (item.id) {
                let param = {};
                param.id = item.id;
                let res = await  http.post(functionMethod, param);
                if (res.code === 200) {
                    ElMessage({
                        message: '删除成功',
                        type: 'success',
                    })
                    if (callback){
                        callback();
                    }
                } else {
                    ElMessage.error(res.msg)
                }
            }
        } catch (error) {
            console.error('删除失败:', error)
        }
    }
    return {handleDelete}

}
